<?php
namespace Yizhidaozuihou;

use Illuminate\Database\Capsule\Manager as DB;
use Elasticsearch\ClientBuilder;

class Elasticsearch
{

    public function __construct()
    {
        echo 111;
        $capsule = new \Illuminate\Database\Capsule\Manager;
        // 创建链接
        $capsule->addConnection([
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'demo',
            'username'  => 'root',
            'password'  => '',
            'charset'   => 'utf8mb4',
            'port'      => 3306,
            'collation' => 'utf8mb4_general_ci',
            'prefix'    => '',
        ]);
        // 设置全局静态可访问DB
        $capsule->setAsGlobal();
        // 启动Eloquent （如果只使用查询构造器，这个可以注释）
        $capsule->bootEloquent();

    }


    public function getOne(array $params)
    {

        $builder = \Model\ChatRecords::query()->where('id', 3);

        $bindings = $builder->getBindings();
        $sql = str_replace('?', '%s', $builder->toSql());
        $sql = str_replace('`', '', $sql);
        $sql = sprintf($sql, ...$bindings);

        var_dump($sql);
    }


}